package com.zhaolixiang.view.draw2

import android.content.Context
import android.graphics.*
import android.view.View

/**
 * Created by Administrator on 2018/1/1.
 */
class MyView(context: Context):View(context) {
    override fun onDraw(canvas: Canvas) {
        super.onDraw(canvas)

        val paint= Paint()
        //抗锯齿
        paint.isAntiAlias=true
        //设置画笔颜色
        paint.color=Color.parseColor("#448ced")
        //设置画笔米描边原来是hi
        paint.style=Paint.Style.STROKE
        //设置画笔宽度
        paint.strokeWidth=5f
        paint.textSize=24f



        //路径
        val path= Path()
        path.moveTo(10f,10f)
        path.lineTo(10f,100f)
        path.lineTo(100f,100f)
        path.lineTo(100f,200f)
        path.close()

        canvas.drawPath(path,paint)


        val str="风萧萧兮易水寒，壮士一去兮不复返"
        //矩形路径:顺时针
        String

        val path2=Path()
        val rectf=RectF(10f,350f,200f,550f)
        path2.addRect(rectf,Path.Direction.CW)
        canvas.drawPath(path2,paint)
        //参数3：沿着路径添加到文本起始位置的距离
        //参数4：上面的距离(-)或下面(+)文本位置的路径
        canvas.drawTextOnPath(str,path2,0f,0f,paint)


        //矩形路径，逆时针
        val path3=Path()
        val rectf2=RectF(250f,350f,450f,550f)
        path3.addRect(rectf2,Path.Direction.CCW)
        canvas.drawPath(path3,paint)
        //参数3：沿着路径添加到文本起始位置的距离
        //参数4：上面的距离(-)或下面(+)文本位置的路径
        canvas.drawTextOnPath(str,path3,0f,0f,paint)

        //圆角矩形路径
        val rectf4=RectF(10f,600f,110f,700f)
        val path4=Path()
        path4.addRoundRect(rectf4,10f,10f,Path.Direction.CW)
        canvas.drawPath(path4,paint)

        val rectf5=RectF(210f,600f,310f,700f)
        val path5=Path()
        val floadList= floatArrayOf(10f,20f,30f,40f,10f,20f,30f,40f)
        path5.addRoundRect(rectf5,floadList,Path.Direction.CW)
        canvas.drawPath(path5,paint)

        //圆形路径
        val path6=Path()
        path6.addCircle(100f,100f,100f,Path.Direction.CW)
        canvas.drawPath(path6, paint)

        //椭圆路径
        val path7=Path()
        val rectf7=RectF(100f,100f,200f,300f)
        path7.addOval(rectf7,Path.Direction.CW)
        canvas.drawPath(path7,paint)

        //圆弧路径
        val path8=Path()
        val rectf8=RectF(200f,200f,300f,300f)
        path8.addArc(rectf8,0f,50f)
        canvas.drawPath(path8,paint)


    }
}